<template>
	<view class="box">
		<view class="top">
			<u-navbar :is-back="true" title="统计"></u-navbar>
		</view>
		<view class="income_order container_B">
			<view class="titleBox jsb">
				<view class="left fb">
					<view class="icon">

					</view>
					<view class="title">
						营收与订单统计
					</view>
				</view>
				<view class="right jsb" @click="()=>this.showDate =true">
					<span>{{year}}年{{month}}月</span>
					<u-icon size="28" :name="'/static/icon/rl.png'"></u-icon>
				</view>
			</view>
			<view class="tabs jsb">
				<view class="item" v-for="item in tabs" :key="item.id" :class="{active:tabId==item.id}"
					@click="selectTab(item.id)">
					{{item.name}}
				</view>
			</view>
			<view class="orderDesc jsb">
				<view class="left item">
					<view class="title">
						总收入
					</view>
					<view class="price num">
						￥788.00
					</view>
					<view class="total">
						待结算￥152
					</view>
				</view>
				<view class="right item">
					<view class="title">
						总收入
					</view>
					<view class="price num">
						68
					</view>
					<view class="total">
						待送达3单
					</view>
				</view>
			</view>
		</view>
		<view class="charts-box">
			<view class="titleBox fb">
				<view class="icon">

				</view>
				<view class="title">
					营收与订单趋势图
				</view>
			</view>
			<!-- <view class="timeType flc">
				<view class="timeTitle">
					时间类型
				</view>
				<view class="item" v-for="item in timeType" :key="item.id" :class="{active:timeId==item.id}"
					@click="selectTime(item.id)">
					{{item.name}}
				</view>
			</view> -->
			<qiun-data-charts type="area" :opts="opts" :chartData="chartData" :ontouch="true" />
		</view>
		<!-- 日历 -->
		<u-calendar v-model="showDate" mode="date" @change="changeDate"></u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 日历
				showDate: false,
				year: "2024",
				month: "11",
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['area'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					color: ["#ff7172", "#1890FF", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 15, 0, 15],
					enableScroll: true,
					legend: {},
					xAxis: {
						disableGrid: true,
						scrollShow: true,
						itemCount: 7,
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2
					},
					extra: {
						area: {
							type: "curve",
							opacity: 0.2,
							addLine: true,
							width: 2,
							gradient: true,
							activeType: "hollow"
						}
					}
				},
				tabId: "0",
				tabs: [{
						id: "0",
						name: '今日',
					},
					{
						id: "1",
						name: "本月"
					}
				],
				timeId: "0",
				timeType: [{
						id: "0",
						name: "近七日"
					},
					{
						id: "1",
						name: "近30天"
					}
				]
			};
		},
		onReady() {
			this.getServerData();
		},
		methods: {
			getServerData() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: ["11.05", "11.06", "11.07", "11.08", "11.09", "11.10", "11.11"],
						series: [{
								name: "消费金额",
								data: [100, 140, 230, 100, 130, 160, 100]
							},
							{
								name: "订单量",
								data: [10, 7, 29, 14, 24, 13, 36]
							}
						]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},
			// 选择日期
			changeDate(e) {
				console.log(e);
				this.year = e.year
				this.month = e.month
			},
			// 选择类型
			selectTab(id) {
				this.tabId = id
				if (id == 0) {
					this.opts.enableScroll = false
				} else {
					this.opts.enableScroll = true
				}
			},
			selectTime(id) {
				this.timeId = id
			}
		}
	};
</script>

<style scoped lang="scss">
	/* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
	.charts-box {
		width: 100%;
		height: 300px;
		margin: 20rpx auto;
		background-color: #fff;
		box-sizing: border-box;
		padding: 20rpx;

		.titleBox {
			font-weight: 600;
			padding: 20rpx 0;
			font-size: 36rpx;
			color: #333333;
			border-bottom: 1rpx solid #dedede;

			.icon {
				width: 8rpx;
				height: 40rpx;
				background: #F5CE31;
				border-radius: 3rpx;
				margin-right: 15rpx;
			}
		}
		.timeType{
			padding: 30rpx 0;
			border-bottom: 1rpx solid #dedede;
			margin-bottom: 30rpx;
			.timeTitle{
				font-size: 28rpx;
				color: #999999;
			}
			.item{
				width: 150rpx;
				height: 56rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				text-align: center;
				line-height: 56rpx;
				font-size: 30rpx;
				color: #333333;
				margin: 0 18rpx;
			}
			.item.active{
				background: #F5CE31;
			}
		}
	}

	.income_order {
		padding: 20rpx 0;

		.titleBox .left {
			font-weight: 600;
			font-size: 36rpx;
			color: #333333;

			.icon {
				width: 8rpx;
				height: 40rpx;
				background: #F5CE31;
				border-radius: 3rpx;
				margin-right: 15rpx;
			}
		}

		.titleBox .right {
			width: 200rpx;
			height: 60rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			border: 1px solid #E6E6E6;
			font-size: 24rpx;
			color: #333333;
			box-sizing: border-box;
			padding: 10rpx 20rpx;
		}

		.tabs {
			border-bottom: 1rpx solid #dedede;
			border-top: 1rpx solid #dedede;

			.item {
				width: 375rpx;
				height: 80rpx;
				text-align: center;
				line-height: 80rpx;
			}

			.item.active {
				background: #F5CE31;
			}
		}
	}

	.orderDesc {
		padding: 20rpx 40rpx;

		.item {
			width: 300rpx;
			height: 160rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;

			.title {
				font-size: 24rpx;
				color: #999999;
			}

			.num {
				font-weight: 600;
				font-size: 36rpx;
				color: #333333;
			}

			.total {
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>